#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

#include <qlistview.h>
#include <qlistwidget.h>
#include <QtGui/QTreeWidget>
#include <QtGui/QTreeView>
#include "../../Cluster.hpp"
#include "../../GraphHandler.hpp"
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>

//#include "dlib/svm.h"
//#include "dlib/rand.h"

//#include <Qt>


namespace Ui {
    class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();

    void PopulateGraphTree();

    //void Cluster(int iK, std::vector<GraphHandler::Graph>& kGraphs);

    void GenerateRandomGraph(GraphHandler::Graph& G,std::vector<std::string>& sNames, std::vector< std::vector<double> >& kMarkov);

    GraphHandler::Graph& NewGraph();

    // For testing purposes of clustering, we may create own graphs
    std::vector<GraphHandler::Graph> m_OwnGraphs;

    void DisplayGraph(const GraphHandler::Graph& G, const GraphHandler::Graph* pOverlay = 0);
    void DisplayGraph(const GraphHandler::Graph& G, std::vector<const GraphHandler::Graph*> pOverlay);
    void ShowPrediction(const GraphHandler::Graph& kHyp);

    // Sets the text in the GUI
    void SetGraphNumber(int i);

    double dSens;
    int iDictSize;

    void AddPartialGraphs(std::vector< std::pair<unsigned int, GraphHandler::Graph> > pgs);

   // void show() {}
//     typedef std::vector<GraphHandler::Graph*> ClusterList;
//std::vector< ClusterList > m_Clusters;

    vector< Cluster* > m_Clusters;
private:
    Ui::MainWindow *ui;

    // The list view items
     QTreeWidgetItem* m_MetaGraphLItem;
     QTreeWidgetItem* m_ClustersLItem;
     QTreeWidgetItem* m_GraphsLItem;
     QTreeWidgetItem* m_OwnGraphsLItem;
     QTreeWidgetItem* m_FreqSubGraphsLItem;
     QTreeWidgetItem* m_PSubgraphs;
     QTreeWidgetItem* m_PartialGraphsExamples;

     // For the graphics
     QGraphicsScene* m_Scn;


     QGraphicsPixmapItem* m_Pic;

     QTreeWidget* m_pGraphTree;

     // So that we can easily retrive the graph for a specific item
     std::map<QTreeWidgetItem*, GraphHandler::Graph*> graphMap;

     // So that we can easily retrive the cluster for a specific item
     std::map<QTreeWidgetItem*, Cluster* > clusterMap;


     std::map<QTreeWidgetItem*, GSpanStruct> freqsubgraphMap;

     std::map< QTreeWidgetItem*, pair<unsigned int, GraphHandler::Graph> > m_PGExamplesMap;

     int m_iCurrentGraphID;;


     // Maintain a unique ID for each string in the users own graphs
     std::map<std::string, int> m_NameMap;
     // A counter which we increment for unique IDs
     int m_iIDCounter;

     void addEdge(GraphHandler::Graph& G, std::string sU, std::string sV);
     void addVertex(GraphHandler::Graph& G, std::string sName);

     void AddCluster(Cluster* pC, QTreeWidgetItem* pRoot);

     GraphHandler::Graph kMoveGraph;
     QTreeWidgetItem* m_pCurrentSelected;
     QTreeWidgetItem* m_pLastSelected;

     GraphHandler::Graph kLastPrediction;

public slots:
    //void GraphItemclicked(QTreeWidgetItem* pItem, int i);
    void GraphItemclicked();

private slots:
    void on_actionCreate_new_graph_triggered();
    void on_newVertex();
    void on_newEdge();
    void on_actionCalculate_distance_triggered();
    void on_nStep();
    void on_nPrediction();
    void on_newRndG();
    void on_moveBtn();
    void on_actionBlacklist_vertex_triggered();
    void on_actionSelect_start_vertex_triggered();
    void on_actionSelect_graph_triggered();
    void on_nBFPrediction();
};

#endif // MAINWINDOW_H





